package com.njitt.bysj.controller;

import com.njitt.bysj.base.BaseController;
import com.njitt.bysj.base.ResultInfo;
import com.njitt.bysj.bean.BomBean;
import com.njitt.bysj.bean.ProductionPickBean;
import com.njitt.bysj.bean.ProjectBean;
import com.njitt.bysj.model.PickModel;
import com.njitt.bysj.query.OutMaterialQuery;
import com.njitt.bysj.query.ProjectProductionQuery;
import com.njitt.bysj.srevice.ProductionPickService;
import com.njitt.bysj.srevice.ProjectService;
import com.njitt.bysj.utils.AssertUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: wyj
 * @time: 2022/4/20 17:02
 */
@Controller
@RequestMapping("production")
public class ProductionController extends BaseController {

    @Resource
    private ProjectService projectService;

    @Resource
    private ProductionPickService pickService;

    @RequestMapping("toProductionPage")
    public String toProductionPage() {
        return "production/toProductionPage";
    }

    @RequestMapping("selectByParamsWithProject")
    @ResponseBody
    public Map<String, Object> selectByParamsWithProject(ProjectProductionQuery query) {
        return projectService.selectByParamsWithProject(query);
    }

    @RequestMapping("detail")
    public String detail(Integer projectId, HttpServletRequest request) {
        ProjectBean projectBean = projectService.selectByPrimaryKey(projectId);
        request.setAttribute("project", projectBean);
        return "production/detail";
    }

    @RequestMapping("toPickMaterial")
    public String toPickMaterial(Integer id, HttpServletRequest request) {
        BomBean bean = projectService.selectByPrimaryBom(id);
        request.setAttribute("bom", bean);
        return "production/pickMaterial";
    }

    @RequestMapping("addPickMaterial")
    @ResponseBody
    public ResultInfo addPickMaterial(ProductionPickBean productionPickBean) {
        pickService.pickMaterial(productionPickBean);
        return success("success");
    }

    @RequestMapping("selectOutMaterial")
    @ResponseBody
    public Map<String, Object> selectOutMaterial(OutMaterialQuery query) {
        /**
         * @description:出库历史
         * @return:  * @param query
         * @author:
         * @time: 2022/4/21 15:12
         */
        return pickService.selectOutMaterial(query);
    }

    @RequestMapping("outUpdateWarehouse")
    @ResponseBody
    public ResultInfo outUpdateWarehouse(Integer id) {
        pickService.outUpdateWarehouse(id);
        return success("success");
    }

    @RequestMapping("supplementMaterial")
    public String supplementMaterial() {
        return "production/supplementMaterial";
    }


    @RequestMapping("addSupplementMaterial")
    @ResponseBody
    public ResultInfo addSupplementMaterial(ProductionPickBean productionPickBean) {
        pickService.addSupplementMaterial(productionPickBean);
        return success("success");
    }

    @RequestMapping("assignSupp")
    @ResponseBody
    public ResultInfo assignSupp(Integer id) {
        pickService.updateAssignSupp(id);
        return success("success");
    }

    @RequestMapping("toQuality")
    @ResponseBody
    public ResultInfo toQuality(String projectNo) {
        pickService.toQuality(projectNo);
        return success("success");
    }

}
